package controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.*;
import javax.servlet.http.*;

import ecommerce.service.ProductoService;
import ecommerce.to.ProductoTO;

public class Imagen extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }

    public void service(HttpServletRequest request, 
                        HttpServletResponse response) throws ServletException, IOException {response.setContentType(CONTENT_TYPE);

            int id = Integer.parseInt(request.getParameter("id"));
            
            ProductoService proSer = new ProductoService();
            
            try{
                
                ProductoTO proTO = proSer.traerPorId(id);
                
                response.setContentType("image/gif");
                
                response.getOutputStream().write(proTO.getImagen());
                
            }catch(Exception ex){
                response.sendRedirect("error.jsp");
            }

    }
}
